#pragma once

#include <defs.h>

/* Network - Adapted from COW */

enum EServerPacketType
{
    EServerPacketType_None = 0,
    EServerPacketType_Message,
    EServerPacketType_PlayerInfo,
    EServerPacketType_PlayerKills,
    EServerPacketType_PlayerLocation,
    EServerPacketType_TorpStatus,
    EServerPacketType_TorpLocation,
    EServerPacketType_Phaser,
    EServerPacketType_PlasmaStatus,
    EServerPacketType_PlasmaLocation,
    EServerPacketType_Warning,
    EServerPacketType_MOTD,
    EServerPacketType_You,
    EServerPacketType_QueueLocation,
    EServerPacketType_GalaxyStatus,
    EServerPacketType_PlanetResourceInfo,
    EServerPacketType_TeamAndShipPickAccepted,
    EServerPacketType_Login,
    EServerPacketType_PlayerFlags,
    EServerPacketType_ValidTeamMask,
    EServerPacketType_PlayerStatus,
    EServerPacketType_BadVersion,
    EServerPacketType_PlayerHostilitySettings,
    EServerPacketType_PlayerStats,
    EServerPacketType_NewPlayerLogin,
    EServerPacketType_Reserved,
    EServerPacketType_PlanetNameAndLocation,
    EServerPacketType_Scan, // NOT IMPLEMENTED
    EServerPacketType_UDPReply,
    EServerPacketType_Sequence,
    EServerPacketType_SemiCriticalSequence,
    EServerPacketType_RSA_Key,

    // 31 to 38 appear invalid
    EServerPacketType_Invalid_31,
    EServerPacketType_Invalid_32,
    EServerPacketType_Invalid_33,
    EServerPacketType_Invalid_34,
    EServerPacketType_Invalid_35,
    EServerPacketType_Invalid_36,
    EServerPacketType_Invalid_37,
    EServerPacketType_Invalid_38,


    EServerPacketType_ShipCapabilities,
    EServerPacketType_Short_SendShortRequestReply,
    EServerPacketType_Short_Message,
    EServerPacketType_Short_Warning,
    EServerPacketType_Short_You,
    EServerPacketType_Short_You_ShipStatus,
    EServerPacketType_Short_Player,

    EServerPacketType_Ping,

    EServerPacketType_Short_TorpLocation,
    EServerPacketType_Short_TorpStatus,
    EServerPacketType_Short_TorpLocationOptimized,
    EServerPacketType_Short_PlanetResources,

    // 51 to 55 appear invalid
    EServerPacketType_Invalid_51,
    EServerPacketType_Invalid_52,
    EServerPacketType_Invalid_53,
    EServerPacketType_Invalid_54,
    EServerPacketType_Invalid_55,
    //
    EServerPacketType_Short_Sequence,
    EServerPacketType_Short_Phaser,
    EServerPacketType_Short_PlayerKills,
    EServerPacketType_Short_PlayerStats,

    EServerPacketType_Feature,
    EServerPacketType_Count,
    EServerPacketType_Max = EServerPacketType_Feature, 

};

enum EClientPacketType
{
    EClientPacketType_None = 0,
    EClientPacketType_Message,
    EClientPacketType_SetSpeed,
    EClientPacketType_SetDirection,
    EClientPacketType_FirePhaser,
    EClientPacketType_FirePlasma,
    EClientPacketType_FireTorp,
    EClientPacketType_Quit,
    EClientPacketType_Login,
    EClientPacketType_OutfitToNewShip,
    EClientPacketType_ChangeWarStatus,
    EClientPacketType_CreatePracticeRobot,
    EClientPacketType_ToggleShields,
    EClientPacketType_EnterRepairMode,
    EClientPacketType_OrbitPlanetOrStarbase,
    EClientPacketType_LockOnToPlanet,
    EClientPacketType_LockOnToPlayer,
    EClientPacketType_BombPlanet,
    EClientPacketType_BeamArmies,
    EClientPacketType_ToggleCloak,
    EClientPacketType_DetEnemyTorps,
    EClientPacketType_DetMyTorps,
    EClientPacketType_CopilotMode,
    EClientPacketType_Refit,
    EClientPacketType_ToggleTractor,
    EClientPacketType_TogglePressor,
    EClientPacketType_CoupHomePlanet,
    EClientPacketType_Socket,
    EClientPacketType_SaveOptions,
    EClientPacketType_Bye,
    EClientPacketType_SetDockPermission,
    EClientPacketType_SetUpdateFrequency,
    EClientPacketType_ResetStats,
    EClientPacketType_Reserved,
    EClientPacketType_Scan,
    EClientPacketType_UDPRequest,
    EClientPacketType_SequenceNumber,
    EClientPacketType_RSAKey,
    EClientPacketType_Invalid38,
    EClientPacketType_Invalid39,
    EClientPacketType_Invalid40,
    EClientPacketType_Invalid41,
    EClientPacketType_PingResponse,
    EClientPacketType_Short_Request,
    EClientPacketType_Short_Thrs, // ????
    EClientPacketType_Short_Message,
    EClientPacketType_Short_Reserved,
    EClientPacketType_Short_Dummy,
    EClientPacketType_Invalid48,
    EClientPacketType_Invalid49,
    EClientPacketType_Invalid50,
    EClientPacketType_Invalid51,
    EClientPacketType_Invalid52,
    EClientPacketType_Invalid53,
    EClientPacketType_Invalid54,
    EClientPacketType_Invalid55,
    EClientPacketType_Invalid56,
    EClientPacketType_Invalid57,
    EClientPacketType_Invalid58,
    EClientPacketType_Invalid59,
    EClientPacketType_Feature,

    EClientPacketType_Count,
    EClientPacketType_Max = EClientPacketType_Feature, 
};

/* variable length packets */
#define VPLAYER_SIZE    4
#define SHORTVERSION    11			 /* other number blocks, like
						  * * * UDP Version */
#define OLDSHORTVERSION 10			 /* S_P2 */

#define SOCKVERSION 	4
#define UDPVERSION      10



struct packet_base {
    char type;
};


struct mesg_spacket {
    char    type;                /* SP_MESSAGE */
    unsigned char m_flags;
    unsigned char m_recpt;
    unsigned char m_from;
    char    mesg[80];

    static void FromNetworkByteOrder(BYTE* pb);
};

struct plyr_info_spacket {
    char    type;                /* SP_PLAYER_INFO */
    char    pnum;
    char    shiptype;
    char    team;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct plyr_login_spacket {
    char    type;                /* SP_PL_LOGIN */
    char    pnum;
    char    rank;
    char    pad1;
    char    name[16];
    char    monitor[16];
    char    login[16];

    static void FromNetworkByteOrder(BYTE* pb);
};

struct hostile_spacket {
    char    type;                /* SP_HOSTILE */
    char    pnum;
    char    war;
    char    hostile;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct stats_spacket {
    char    type;                /* SP_STATS */
    char    pnum;
    char    pad1;
    char    pad2;
    LONG    tkills;              /* Tournament kills */
    LONG    tlosses;                 /* Tournament losses */
    LONG    kills;               /* overall */
    LONG    losses;              /* overall */
    LONG    tticks;              /* ticks of tournament play
                          * * * time */
    LONG    tplanets;                /* Tournament planets */
    LONG    tarmies;                 /* Tournament armies */
    LONG    sbkills;                 /* Starbase kills */
    LONG    sblosses;                /* Starbase losses */
    LONG    armies;              /* non-tourn armies */
    LONG    planets;                 /* non-tourn planets */
    LONG    maxkills;                /* max kills as player * 100 
                          * 
                          */
    LONG    sbmaxkills;              /* max kills as sb * 100 */

    static void FromNetworkByteOrder(BYTE* pb);
};

struct flags_spacket {
    char    type;                /* SP_FLAGS */
    char    pnum;                /* whose flags are they? */
    char    pad1;
    char    pad2;
    unsigned flags;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct kills_spacket {
    char    type;                /* SP_KILLS */
    char    pnum;
    char    pad1;
    char    pad2;
    unsigned kills;              /* where 1234=12.34 kills *
                          * * and 0=0.00 kills */

    static void FromNetworkByteOrder(BYTE* pb);
};

struct player_spacket {
    char    type;                /* SP_PLAYER */
    char    pnum;
    unsigned char dir;
    char    speed;
    LONG    x, y;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct torp_info_spacket {
    char    type;                /* SP_TORP_INFO */
    char    war;
    char    status;              /* TFREE, TDET, etc... */
    char    pad1;                /* pad needed for cross cpu
                          * * * compatibility */
    unsigned short tnum;
    unsigned short pad2;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct torp_spacket {
    char    type;                /* SP_TORP */
    unsigned char dir;           // MAY NOT BE SET BY SERVER -- DO NOT USE
    unsigned short tnum;
    LONG    x, y;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct phaser_spacket {
    char    type;                /* SP_PHASER */
    char    pnum;
    char    status;              /* PH_HIT, etc... */
    unsigned char dir;
    LONG    x, y;
    LONG    target;  // Player ID

    static void FromNetworkByteOrder(BYTE* pb);
};

struct you_spacket {
    char    type;                /* SP_YOU */
    char    pnum;                /* Guy needs to know this... 
                          * 
                          */
    char    hostile;
    char    swar;
    char    armies;
    char    pad1;
    char    pad2;
    char    pad3;
    unsigned flags;
    LONG    damage;
    LONG    shield;
    LONG    fuel;
    unsigned short etemp;
    unsigned short wtemp;
    unsigned short whydead;
    unsigned short whodead;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct status_spacket {
    char    type;                /* SP_STATUS */
    char    tourn;
    char    pad1;
    char    pad2;
    unsigned armsbomb;
    unsigned planets;
    unsigned kills;
    unsigned losses;
    unsigned time;
    DWORD timeprod;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct warning_spacket {
    char    type;                /* SP_WARNING */
    char    pad1;
    char    pad2;
    char    pad3;
    char    mesg[80];

    static void FromNetworkByteOrder(BYTE* pb);

};

struct planet_spacket {
    char    type;                /* SP_PLANET */
    char    pnum;
    char    owner;
    char    info;
    unsigned short flags;
    unsigned short pad2;
    LONG    armies;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct torp_cpacket {
    char    type;                /* CP_TORP */
    unsigned char dir;               /* direction to fire torp */
    char    pad1;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct phaser_cpacket {
    char    type;                /* CP_PHASER */
    unsigned char dir;
    char    pad1;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct speed_cpacket {
    char    type;                /* CP_SPEED */
    char    speed;
    char    pad1;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct dir_cpacket {
    char    type;                /* CP_DIRECTION */
    unsigned char dir;
    char    pad1;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct shield_cpacket {
    char    type;                /* CP_SHIELD */
    char    state;               /* up/down */
    char    pad1;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);

};

struct repair_cpacket {
    char    type;                /* CP_REPAIR */
    char    state;               /* on/off */
    char    pad1;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct orbit_cpacket {
    char    type;                /* CP_ORBIT */
    char    state;               /* on/off */
    char    pad1;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct practr_cpacket {
    char    type;                /* CP_PRACTR */
    char    pad1;
    char    pad2;
    char    pad3;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct bomb_cpacket {
    char    type;                /* CP_BOMB */
    char    state;
    char    pad1;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct beam_cpacket {
    char    type;                /* CP_BEAM */
    char    state;
    char    pad1;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct cloak_cpacket {
    char    type;                /* CP_CLOAK */
    char    state;
    char    pad1;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct det_torps_cpacket {
    char    type;                /* CP_DET_TORPS */
    char    pad1;
    char    pad2;
    char    pad3;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct copilot_cpacket {
    char    type;                /* CP_COPLIOT */
    char    state;
    char    pad1;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct queue_spacket {
    char    type;                /* SP_QUEUE */
    char    pad1;
    unsigned short pos;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct outfit_cpacket {
    char    type;                /* CP_OUTFIT */
    char    team;
    char    ship;
    char    pad1;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct pickok_spacket {
    char    type;                /* SP_PICKOK */
    char    state;
    char    pad2;
    char    pad3;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct login_cpacket {
    char    type;                /* CP_LOGIN */
    char    query;
    char    pad2;
    char    pad3;
    char    name[16];
    char    password[16];
    char    login[16];

    static void ToNetworkByteOrder(BYTE* pb);
};

struct login_spacket {
    char    type;                /* SP_LOGIN */
    char    accept;              /* 1/0 */
    char    pad2;
    char    pad3;
    LONG    flags;
    char    keymap[96];

    static void FromNetworkByteOrder(BYTE* pb);
};

struct tractor_cpacket {
    char    type;                /* CP_TRACTOR */
    char    state;
    char    pnum;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct repress_cpacket {
    char    type;                /* CP_REPRESS */
    char    state;
    char    pnum;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct det_mytorp_cpacket {
    char    type;                /* CP_DET_MYTORP */
    char    pad1;
    unsigned short tnum;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct war_cpacket {
    char    type;                /* CP_WAR */
    char    newmask;
    char    pad1;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct refit_cpacket {
    char    type;                /* CP_REFIT */
    char    ship;
    char    pad1;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct plasma_cpacket {
    char    type;                /* CP_PLASMA */
    unsigned char dir;
    char    pad1;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct plasma_info_spacket {
    char    type;                /* SP_PLASMA_INFO */
    char    war;
    char    status;              /* TFREE, TDET, etc... */
    char    pad1;                /* pad needed for cross cpu
                          * * * compatibility */
    unsigned short pnum;
    unsigned short pad2;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct plasma_spacket {
    char    type;                /* SP_PLASMA */
    char    pad1;
    unsigned short pnum;
    LONG    x, y;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct playlock_cpacket {
    char    type;                /* CP_PLAYLOCK */
    char    pnum;
    char    pad1;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct planlock_cpacket {
    char    type;                /* CP_PLANLOCK */
    char    pnum;
    char    pad1;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);

};

struct coup_cpacket {
    char    type;                /* CP_COUP */
    char    pad1;
    char    pad2;
    char    pad3;

    static void ToNetworkByteOrder(BYTE* pb);

};

struct pstatus_spacket {
    char    type;                /* SP_PSTATUS */
    char    pnum;
    char    status;
    char    pad1;

    static void FromNetworkByteOrder(BYTE* pb);

};

struct motd_spacket {
    char    type;                /* SP_MOTD */
    char    pad1;
    char    pad2;
    char    pad3;
    char    line[80];

    static void FromNetworkByteOrder(BYTE* pb);
};

struct quit_cpacket {
    char    type;                /* CP_QUIT */
    char    pad1;
    char    pad2;
    char    pad3;

    static void ToNetworkByteOrder(BYTE* pb);

};

struct mesg_cpacket {
    char    type;                /* CP_MESSAGE */
    char    group;
    char    indiv;
    char    pad1;
    char    mesg[80];

    static void ToNetworkByteOrder(BYTE* pb);
};

struct mask_spacket {
    char    type;                /* SP_MASK */
    char    mask;
    char    pad1;
    char    pad2;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct socket_cpacket {
    char    type;                /* CP_SOCKET */
    char    version;
    char    udp_version;             /* was pad2 */
    char    pad3;
    unsigned socket;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct options_cpacket {
    char    type;                /* CP_OPTIONS */
    char    pad1;
    char    pad2;
    char    pad3;
    unsigned flags;
    char    keymap[96];

    static void ToNetworkByteOrder(BYTE* pb);
};

struct bye_cpacket {
    char    type;                /* CP_BYE */
    char    pad1;
    char    pad2;
    char    pad3;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct badversion_spacket {
    char    type;                /* SP_BADVERSION */
    char    why;
    char    pad2;
    char    pad3;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct dockperm_cpacket {
    char    type;                /* CP_DOCKPERM */
    char    state;
    char    pad2;
    char    pad3;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct updates_cpacket {
    char    type;                /* CP_UPDATES */
    char    pad1;
    char    pad2;
    char    pad3;
    unsigned usecs;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct resetstats_cpacket {
    char    type;                /* CP_RESETSTATS */
    char    verify;              /* 'Y' - just to make sure * 
                          * 
                          * * he meant it */
    char    pad2;
    char    pad3;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct reserved_spacket {
    char    type;                /* SP_RESERVED */
    char    pad1;
    char    pad2;
    char    pad3;
    char    data[16];

    static void FromNetworkByteOrder(BYTE* pb);
};

struct reserved_cpacket {
    char    type;                /* CP_RESERVED */
    char    pad1;
    char    pad2;
    char    pad3;
    char    data[16];
    char    resp[16];

    static void ToNetworkByteOrder(BYTE* pb);
};

struct udp_req_cpacket {                      /* UDP */
    char    type;                /* CP_UDP_REQ */
    char    request;
    char    connmode;                /* respond with port # or *
                          * * just send UDP packet? */
    char    pad2;
    int     port;                /* compensate for hosed * *
                          * recvfrom() */
    static void ToNetworkByteOrder(BYTE* pb);
};
struct ping_cpacket {
    char    type;                /* CP_PING_RESPONSE */
    unsigned char number;            /* id */
    char    pingme;              /* if client wants server to
                          * * * ping */
    char    pad1;

    LONG    cp_sent;                 /* # packets sent to server */
    LONG    cp_recv;                 /* # packets recv from * *
                          * server */
    static void ToNetworkByteOrder(BYTE* pb);
};
struct ping_spacket {
    char    type;                /* SP_PING */
    unsigned char number;            /* id (ok to wrap) */
    unsigned short lag;              /* delay of last ping in ms */

    unsigned char tloss_sc;          /* total loss server-client
                          * * * 0-100% */
    unsigned char tloss_cs;          /* total loss client-server
                          * * * 0-100% */

    unsigned char iloss_sc;          /* inc. loss server-client * 
                          * 
                          * * 0-100% */
    unsigned char iloss_cs;          /* inc. loss client-server * 
                          * 
                          * * 0-100% */

    static void FromNetworkByteOrder(BYTE* pb);
};
struct sequence_cpacket {                      /* UDP */
    char    type;                /* CP_SEQUENCE */
    char    pad1;
    unsigned short sequence;

    static void ToNetworkByteOrder(BYTE* pb);
};


struct sc_sequence_spacket {                      /* UDP */
    char    type;                /* SP_CP_SEQUENCE */
    char    pad1;
    unsigned short sequence;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct udp_reply_spacket {                      /* UDP */
    char    type;                /* SP_UDP_REPLY */
    char    reply;
    char    pad1;
    char    pad2;
    int     port;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct sequence_spacket {                      /* UDP */
    char    type;                /* SP_SEQUENCE */
    unsigned char flag16;
    unsigned short sequence;

    static void FromNetworkByteOrder(BYTE* pb);
};


struct planet_loc_spacket {
    char    type;                /* SP_PLANET_LOC */
    char    pnum;
    char    pad2;
    char    pad3;
    LONG    x;
    LONG    y;
    char    name[16];

    static void FromNetworkByteOrder(BYTE* pb);
};

struct feature_cpacket {
    char    type;
    char    feature_type;
    char    arg1, arg2;
    int     value;
    char    name[80];

    static void ToNetworkByteOrder(BYTE* pb);
    static void FromNetworkByteOrder(BYTE* pb);
};

struct rsa_key_spacket {
    char    type;                /* SP_RSA_KEY */
    char    pad1;
    char    pad2;
    char    pad3;
    unsigned char data[c_uiKeySize];

    static void FromNetworkByteOrder(BYTE* pb);
};

struct rsa_key_cpacket {
    char    type;                /* CP_RSA_KEY */
    char    pad1;
    char    pad2;
    char    pad3;
    unsigned char global[c_uiKeySize];
    unsigned char publicKey[c_uiKeySize];
    unsigned char resp[c_uiKeySize];

    static void ToNetworkByteOrder(BYTE* pb);
};

struct ship_cap_spacket {                      /* Server configuration of * 
                                                * 
                                                * * client */
    char    type;                /* screw motd method */
    char    operation;               /* 0 = add/change a ship, 1
                          * * * = remove a ship */
    unsigned short s_type;           /* SP_SHIP_CAP */
    unsigned short s_torpspeed;
    unsigned short s_phaserrange;
    int     s_maxspeed;
    int     s_maxfuel;
    int     s_maxshield;
    int     s_maxdamage;
    int     s_maxwpntemp;
    int     s_maxegntemp;
    unsigned short s_width;
    unsigned short s_height;
    unsigned short s_maxarmies;
    char    s_letter;
    char    pad2;
    char    s_name[16];
    char    s_desig1;
    char    s_desig2;
    unsigned short s_bitmap;

    static void FromNetworkByteOrder(BYTE* pb);
};

struct shortreq_cpacket {                      /* CP_S_REQ */
    char    type;
    char    req;
    char    version;
    char    pad2;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct threshold_cpacket {                      /* CP_S_THRS */
    char    type;
    char    pad1;
    unsigned short thresh;

    static void ToNetworkByteOrder(BYTE* pb);
};

struct shortreply_spacket {                      /* SP_S_REPLY */
    char    type;
    char    repl;
    unsigned short winside;
    LONG    gwidth;

    static void FromNetworkByteOrder(BYTE* pb);
};

// FOLLOWING ARE SHORT PACKETS - VARIABLE LENGTH AND STRUCTURE.


struct youshort_spacket {                      /* SP_S_YOU */
    char    type;

    char    pnum;
    char    hostile;
    char    swar;

    char    armies;
    char    whydead;
    char    whodead;

    char    pad1;

    unsigned flags;

};

struct youss_spacket {                      /* SP_S_YOU_SS */
    char    type;
    char    pad1;

    unsigned short damage;
    unsigned short shield;
    unsigned short fuel;
    unsigned short etemp;
    unsigned short wtemp;
};

#define VPLANET_SIZE 6

struct planet_s_spacket {                      /* body of SP_S_PLANET  */
    char    pnum;
    char    owner;
    char    info;
    unsigned char armies;            /* more than 255 Armies ? *
                          * * ...  */
    unsigned short flags;
};
struct warning_s_spacket {                      /* SP_S_WARNING */
    char    type;
    unsigned char whichmessage;
    char    argument, argument2;         /* for phaser  etc ... */
};

struct player_s_spacket {
    char    type;                /* SP_S_PLAYER Header */
    char    packets;                 /* How many player-packets * 
                          * 
                          * * are in this packet (
                          * only * * the first 6 bits 
                          * are * * relevant ) */
    unsigned char dir;
    char    speed;
    LONG    x, y;                /* To get the absolute * *
                          * Position */
};

/* S_P2 */
struct player_s2_spacket {
    char    type;                /* SP_S_PLAYER Header */
    char    packets;                 /* How many player-packets * 
                          * 
                          * * are in this packet  ( *
                          * * only the firs t 6 bits *
                          * * are relevant ) */
    unsigned char dir;
    char    speed;
    short   x, y;                /* absolute position / 40 */
    unsigned int flags;              /* 16 playerflags */
};

/* The format of the body: struct player_s_body_spacket {       Body of new
 * Player Packet unsigned char pnum;   0-4 = pnum, 5 local or galactic, 6 =
 * 9. x-bit, 7 9. y-bit unsigned char speeddir;       0-3 = speed , 4-7
 * direction of ship unsigned char x;      low 8 bits from X-Pixelcoordinate
 * unsigned char y;      low 8 bits from Y-Pixelcoordinate }; */

struct torp_s_spacket {
    char    type;                /* SP_S_TORP */
    unsigned char bitset;            /* bit=1 that torp is in * * 
                          * packet */
    unsigned char whichtorps;            /* Torpnumber of first torp
                          * * * / 8 */
    unsigned char data[21];          /* For every torp 2*9 bit *
                          * * coordinates */
};

struct mesg_s_spacket {
    char    type;                /* SP_S_MESSAGE */
    unsigned char m_flags;
    unsigned char m_recpt;
    unsigned char m_from;
    unsigned char length;            /* Length of whole packet */
    char    mesg;
    char    pad2;
    char    pad3;
    char    pad[76];
};

struct mesg_s_cpacket {
    char    type;                /* CP_S__MESSAGE */
    char    group;
    char    indiv;
    char    length;              /* Size of whole packet   */
    char    mesg[80];
};

/* S_P2 */
struct kills_s_spacket {
    char    type;                /* SP_S_KILLS */
    char    pnum;                /* How many kills in packet */
    unsigned short kills;            /* 6 bit player numer   */
    /* 10 bit kills*100     */
    unsigned short mkills[c_uiMaxPlayers];
};

struct phaser_s_spacket {
    char    type;                /* SP_S_PHASER */
    char    status;              /* PH_HIT, etc... */
    unsigned char pnum;              /* both bytes are used for * 
                          * 
                          * * more */
    unsigned char target;            /* look into the code   */
    short   x;                   /* x coord /40 */
    short   y;                   /* y coord /40 */
    unsigned char dir;
    char    pad1;
    char    pad2;
    char    pad3;
};

struct stats_s_spacket {
    char    type;                /* SP_S_STATS */
    char    pnum;
    unsigned short tplanets;             /* Tournament planets */
    unsigned short tkills;           /* Tournament kills */
    unsigned short tlosses;          /* Tournament losses */
    unsigned short kills;            /* overall */
    unsigned short losses;           /* overall */
    unsigned int tticks;             /* ticks of tournament play
                          * * * time */
    unsigned int tarmies;            /* Tournament armies */
    unsigned int maxkills;
    unsigned short sbkills;          /* Starbase kills */
    unsigned short sblosses;             /* Starbase losses */
    unsigned short armies;           /* non-tourn armies */
    unsigned short planets;          /* non-tourn planets */
    unsigned int sbmaxkills;             /* max kills as sb * 100 */
};



class CPacket
{
public:
    static int GetServerPacketLen(EServerPacketType ePacketType);
    static int GetClientPacketLen(EClientPacketType ePacketType);
    static void ToNetworkByteOrder(packet_base* pPacket);
    static void FromNetworkByteOrder(packet_base* pPacket);
    static const char* GetPacketName(EServerPacketType ePacketType);
};
